package com.example.demo.controller;

import com.example.demo.model.Reservation;
import com.example.demo.server.frontServer;
import com.example.demo.util.Alipay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;


@Controller  //控制器
public class FrontController {

    private Alipay alipay;
    @Autowired  //自动注入
    public void setAlipay(Alipay alipay) {
        this.alipay = alipay;
    }
    @Autowired
    public frontServer server;
    //前台打开登录页面
    @GetMapping("/") //提交方式
    public  String index(){
        return "index1";
    }

    //后台登录页面
    @GetMapping("/i")
    public  String index3(){
        return "login1";
    }

    //前台定台页面
    @GetMapping("/create")
    public String create(String name,String email, String money,String phone,Reservation reservation, Model model){
        System.out.println(email);
        String pay = alipay.pay(email,phone,money,name);
        System.out.println(reservation);
        server.add(reservation);
        model.addAttribute("pay",pay);
        return "pay";

    }

    //成功返回 订单查询页面
    @GetMapping("/return")
    public String returnNotice(String out_trade_no,Model model){
        String query = alipay.query(out_trade_no);
        System.out.println(query);
        model.addAttribute("query",query);
        return "index";
    }

    @GetMapping("/notify")
    public void notifyUrl(String trade_no,String total_amount,String trade_status){
        System.err.println("订单编号"+trade_no+",订单金额"+total_amount+",订单状态"+trade_status);
    }
}
